222B - Cosmic Tables - CodeForces Solution


data structures implementation *1300

Please click on ads to support us..

C++ Code:

#include "bits/stdc++.h"
using namespace std;
typedef long long int ll;
#define pb push_back
int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n,m,k;
    cin>>n>>m>>k;
    map<int,int>row,col;
    vector<vector<int>>matrix;
    for(int i=0;i<n;i++)
    {
        row[i] = i;
        vector<int>v;
        for(int j=0;j<m;j++)
        {
            int x;
            cin>>x;
            v.pb( x );
        }
        matrix.pb( v );
    }
    for(int i=0;i<m;i++)
        col[i] = i;

    while( k-- )
    {
        char a; cin>>a;
        int b,c; cin>>b>>c;
        b--; c--;

        if( a == 'r' )
        {
            int temp = row[b];
            row[b] = row[c];
            row[c] = temp;
        }
        else if( a == 'c' )
        {
            int temp = col[b];
            col[b] = col[c];
            col[c] = temp;
        }
        else
            cout << matrix[row[b]][col[c]] << '\n';
    }
}


Comments

Submit
0 Comments
More Questions

1711A - Perfect Permutation
1701B - Permutation
1692A - Marathon
1066A - Vova and Train
169B - Replacing Digits
171D - Broken checker
380C - Sereja and Brackets
1281B - Azamon Web Services
1702A - Round Down the Price
1681C - Double Sort
12A - Super Agent
1709A - Three Doors
1680C - Binary String
1684B - Z mod X = C
1003A - Polycarp's Pockets
1691B - Shoe Shuffling
1706A - Another String Minimization Problem
1695B - Circle Game
1702B - Polycarp Writes a String from Memory
1701A - Grass Field
489C - Given Length and Sum of Digits
886B - Vlad and Cafes
915A - Garden
356A - Knight Tournament
1330A - Dreamoon and Ranking Collection
1692B - All Distinct
1156C - Match Points
1675A - Food for Animals
1328C - Ternary XOR
1689A - Lex String